package com.global.gbinventory.data.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;

public class SupplierFrame extends JInternalFrame {

	private static final long serialVersionUID = 1535697619335370307L;
	
	private JPanel panelButtons;
	private JPanel panelInfoSupplier;
	
	private JTextField txtFldKodeSupplier;
	private JTextField txtFldNamaSupplier;
	private JTextArea txtAreaAlamat;
	private JTextField txtFldKota;
	private JTextField txtFldKodePos;
	private JTextField txtFldProvinsi;
	private JTextField txtFldTelepon;
	
	private JTextField txtFldNamaAgen;
	private JTextField txtFldHpAgen;
	private JTextField txtFldEmailAgen;

	private JTextArea txtAreaKeterangan;
	
	private JButton btnNew;
	private JButton btnEdit;
	private JButton btnDelete;
	private JButton btnSave;
	private JButton btnCancel;
	private JButton btnShowList;

	/**
	 * Create the frame.
	 */
	public SupplierFrame() {
		//resizeable, closeable, maximizable, iconifiable
		super("Setup Supplier", true, true, true, true);
		getContentPane().setPreferredSize(new Dimension(800, 480));
		setBounds(100, 100, 182, 127);
		getContentPane().setLayout(new BorderLayout(0, 0));

		JPanel panelRight = new JPanel();
		panelRight.setPreferredSize(new Dimension(30, 10));
		getContentPane().add(panelRight, BorderLayout.EAST);

		JPanel panelCenter = new JPanel();
		getContentPane().add(panelCenter, BorderLayout.CENTER);
		panelCenter.setLayout(null);

		panelButtons = new JPanel();
		panelButtons.setBorder(new LineBorder(new Color(0, 0, 0)));
		panelButtons.setBounds(20, 11, 744, 40);
		panelCenter.add(panelButtons);
		panelButtons.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

		btnNew = new JButton("New");
		panelButtons.add(btnNew);
		
		btnEdit = new JButton("Edit");
		btnEdit.setEnabled(false);
		panelButtons.add(btnEdit);
		
		btnDelete = new JButton("Delete");
		btnDelete.setEnabled(false);
		panelButtons.add(btnDelete);
		
		btnSave = new JButton("Save");
		btnSave.setEnabled(false);
		panelButtons.add(btnSave);
		
		btnCancel = new JButton("Cancel");
		btnCancel.setEnabled(false);
		panelButtons.add(btnCancel);
		
		panelInfoSupplier = new JPanel();
		panelInfoSupplier.setBorder(new LineBorder(new Color(0, 0, 0)));
		panelInfoSupplier.setBounds(20, 63, 744, 373);
		panelCenter.add(panelInfoSupplier);
		panelInfoSupplier.setLayout(null);
		
		btnShowList = new JButton("...");
		btnShowList.setBounds(305, 32, 24, 23);
		panelInfoSupplier.add(btnShowList);

		JLabel lblInfoUmum = new JLabel("Info Umum");
		lblInfoUmum.setOpaque(true);
		lblInfoUmum.setBackground(new Color(102, 153, 204));
		lblInfoUmum.setBounds(10, 11, 316, 14);
		panelInfoSupplier.add(lblInfoUmum);

		JLabel lblKodeSupplier = new JLabel("Kode Supplier* : ");
		lblKodeSupplier.setBounds(10, 36, 111, 14);
		panelInfoSupplier.add(lblKodeSupplier);

		txtFldKodeSupplier = new JTextField();
		txtFldKodeSupplier.setEditable(false);
		txtFldKodeSupplier.setBounds(122, 33, 173, 20);
		panelInfoSupplier.add(txtFldKodeSupplier);
		txtFldKodeSupplier.setColumns(20);

		JLabel lblNamaSupplier = new JLabel("Nama Supplier* : ");
		lblNamaSupplier.setBounds(10, 67, 111, 14);
		panelInfoSupplier.add(lblNamaSupplier);

		txtFldNamaSupplier = new JTextField();
		txtFldNamaSupplier.setEditable(false);
		txtFldNamaSupplier.setBounds(122, 64, 204, 20);
		panelInfoSupplier.add(txtFldNamaSupplier);
		txtFldNamaSupplier.setColumns(40);

		JLabel lblInfoAgen = new JLabel("Info Agen");
		lblInfoAgen.setOpaque(true);
		lblInfoAgen.setBackground(new Color(102, 153, 204));
		lblInfoAgen.setBounds(10, 98, 316, 14);
		panelInfoSupplier.add(lblInfoAgen);

		JLabel lblNamaAgen = new JLabel("Nama Agen* :");
		lblNamaAgen.setBounds(10, 123, 95, 14);
		panelInfoSupplier.add(lblNamaAgen);

		JLabel lblHpAgen = new JLabel("No HP* :");
		lblHpAgen.setBounds(10, 157, 95, 14);
		panelInfoSupplier.add(lblHpAgen);

		txtFldNamaAgen = new JTextField();
		txtFldNamaAgen.setEditable(false);
		txtFldNamaAgen.setColumns(50);
		txtFldNamaAgen.setBounds(122, 120, 204, 20);
		panelInfoSupplier.add(txtFldNamaAgen);

		txtFldHpAgen = new JTextField();
		txtFldHpAgen.setEditable(false);
		txtFldHpAgen.setColumns(20);
		txtFldHpAgen.setBounds(122, 154, 204, 20);
		panelInfoSupplier.add(txtFldHpAgen);

		JLabel lblInfoAlamat = new JLabel("Info Alamat");
		lblInfoAlamat.setBackground(new Color(102, 153, 204));
		lblInfoAlamat.setOpaque(true);
		lblInfoAlamat.setBounds(351, 11, 383, 14);
		panelInfoSupplier.add(lblInfoAlamat);

		JLabel lblAlamat = new JLabel("Alamat : ");
		lblAlamat.setBounds(351, 36, 72, 14);
		panelInfoSupplier.add(lblAlamat);

		txtAreaAlamat = new JTextArea();
		txtAreaAlamat.setEditable(false);
		txtAreaAlamat.setBounds(418, 31, 316, 77);
		panelInfoSupplier.add(txtAreaAlamat);

		JLabel lblKota = new JLabel("Kota : ");
		lblKota.setBounds(351, 123, 46, 14);
		panelInfoSupplier.add(lblKota);

		txtFldKota = new JTextField();
		txtFldKota.setEditable(false);
		txtFldKota.setBounds(415, 120, 111, 20);
		panelInfoSupplier.add(txtFldKota);
		txtFldKota.setColumns(30);

		JLabel lblKodePos = new JLabel("Kode Pos : ");
		lblKodePos.setBounds(550, 123, 78, 14);
		panelInfoSupplier.add(lblKodePos);

		txtFldKodePos = new JTextField();
		txtFldKodePos.setEditable(false);
		txtFldKodePos.setBounds(623, 120, 111, 20);
		panelInfoSupplier.add(txtFldKodePos);
		txtFldKodePos.setColumns(10);

		JLabel lblProvinsi = new JLabel("Provinsi : ");
		lblProvinsi.setBounds(351, 157, 72, 14);
		panelInfoSupplier.add(lblProvinsi);

		txtFldProvinsi = new JTextField();
		txtFldProvinsi.setEditable(false);
		txtFldProvinsi.setBounds(415, 154, 111, 20);
		panelInfoSupplier.add(txtFldProvinsi);
		txtFldProvinsi.setColumns(30);
		txtFldProvinsi.setText("Sumatera Utara");

		JLabel lblNoTelepon = new JLabel("Telepon : ");
		lblNoTelepon.setBounds(550, 157, 73, 14);
		panelInfoSupplier.add(lblNoTelepon);

		txtFldTelepon = new JTextField();
		txtFldTelepon.setEditable(false);
		txtFldTelepon.setColumns(15);
		txtFldTelepon.setBounds(623, 154, 111, 20);
		panelInfoSupplier.add(txtFldTelepon);

		JLabel lblKeterangan = new JLabel("Keterangan");
		lblKeterangan.setBackground(new Color(102, 153, 204));
		lblKeterangan.setOpaque(true);
		lblKeterangan.setBounds(10, 213, 724, 14);
		panelInfoSupplier.add(lblKeterangan);

		txtAreaKeterangan = new JTextArea();
		txtAreaKeterangan.setEditable(false);
		txtAreaKeterangan.setBounds(10, 238, 724, 88);
		panelInfoSupplier.add(txtAreaKeterangan);

		JLabel lblEmailAgen = new JLabel("Email :");
		lblEmailAgen.setBounds(10, 188, 95, 14);
		panelInfoSupplier.add(lblEmailAgen);

		txtFldEmailAgen = new JTextField();
		txtFldEmailAgen.setEditable(false);
		txtFldEmailAgen.setColumns(50);
		txtFldEmailAgen.setBounds(122, 185, 204, 20);
		panelInfoSupplier.add(txtFldEmailAgen);

		JPanel panelNB = new JPanel();
		FlowLayout fl_panelNB = (FlowLayout) panelNB.getLayout();
		fl_panelNB.setAlignment(FlowLayout.LEFT);
		panelNB.setBounds(20, 447, 744, 25);
		panelCenter.add(panelNB);

		JLabel lblNb = new JLabel("NB : * Harus diisi");
		panelNB.add(lblNb);

		pack();

	}
	
	public void displayFrame(boolean state){
		setVisible(state);
	}
	
	public void addBtnNewListener(ActionListener l){
		btnNew.addActionListener(l);
	}
	
	public void addBtnEditListener(ActionListener l){
		btnEdit.addActionListener(l);
	}
	
	public void addBtnDeleteListener(ActionListener l){
		btnDelete.addActionListener(l);
	}
	
	public void addBtnSaveListener(ActionListener l){
		btnSave.addActionListener(l);
	}
	
	public void addBtnCancelListener(ActionListener l){
		btnCancel.addActionListener(l);
	}
	
	public void addBtnShowListListener(ActionListener l){
		btnShowList.addActionListener(l);
	}
	
	public void requestFocusTxtFldKode(){
		txtFldKodeSupplier.requestFocusInWindow();
	}
	
	public void setEnabledBtnNew(boolean state){
		btnNew.setEnabled(state);
	}
	
	public void setEnabledBtnEdit(boolean state){
		btnEdit.setEnabled(state);
	}
	
	public void setEnabledBtnDelete(boolean state){
		btnDelete.setEnabled(state);
	}
	
	public void setEnabledBtnSave(boolean state){
		btnSave.setEnabled(state);
	}
	
	public void setEnabledBtnCancel(boolean state){
		btnCancel.setEnabled(state);
	}
	
	public void setEnabledBtnShowList(boolean state){
		btnShowList.setEnabled(state);
	}
	
	public String getKode() {
		return txtFldKodeSupplier.getText();
	}
	
	public void setKode(String text){
		txtFldKodeSupplier.setText(text);
	}

	public String getNama() {
		return txtFldNamaSupplier.getText();
	}

	public void setNama(String text){
		txtFldNamaSupplier.setText(text);
	}
	
	public String getNamaAgen() {
		return txtFldNamaAgen.getText();
	}

	public void setNamaAgen(String text){
		txtFldNamaAgen.setText(text);
	}
	
	public String getHpAgen() {
		return txtFldHpAgen.getText();
	}
	
	public void setHpAgen(String text){
		txtFldHpAgen.setText(text);
	}

	public String getEmailAgen() {
		return txtFldEmailAgen.getText();
	}
	
	public void setEmailAgen(String text){
		txtFldEmailAgen.setText(text);
	}

	public String getKota() {
		return txtFldKota.getText();
	}
	
	public void setKota(String text){
		txtFldKota.setText(text);
	}

	public String getKodePos() {
		return txtFldKodePos.getText();
	}

	public void setKodePos(String text){
		txtFldKodePos.setText(text);
	}
	
	public String getProvinsi() {
		return txtFldProvinsi.getText();
	}
	
	public void setProvinsi(String text){
		txtFldProvinsi.setText(text);
	}

	public String getTelepon() {
		return txtFldTelepon.getText();
	}
	
	public void setTelepon(String text){
		txtFldTelepon.setText(text);
	}

	public String getKeterangan() {
		return txtAreaKeterangan.getText();
	}
	
	public void setKeterangan(String text){
		txtAreaKeterangan.setText(text);
	}

	public String getAlamat() {
		return txtAreaAlamat.getText();
	}
	
	public void setAlamat(String text){
		txtAreaAlamat.setText(text);
	}
	
	public void setTextFieldEditable(){
		txtFldKodeSupplier.setEditable(true);
		txtFldNamaSupplier.setEditable(true);
		txtFldNamaAgen.setEditable(true);
		txtFldHpAgen.setEditable(true);
		txtFldEmailAgen.setEditable(true);
		txtFldKodePos.setEditable(true);
		txtFldKota.setEditable(true);
		txtFldTelepon.setEditable(true);
		txtFldProvinsi.setEditable(true);
		txtAreaAlamat.setEditable(true);
		txtAreaKeterangan.setEditable(true);
	}
	
	public void setTextFieldNonEditable(){
		txtFldKodeSupplier.setEditable(false);
		txtFldNamaSupplier.setEditable(false);
		txtFldNamaAgen.setEditable(false);
		txtFldHpAgen.setEditable(false);
		txtFldEmailAgen.setEditable(false);
		txtFldKodePos.setEditable(false);
		txtFldKota.setEditable(false);
		txtFldTelepon.setEditable(false);
		txtFldProvinsi.setEditable(false);
		txtAreaAlamat.setEditable(false);
		txtAreaKeterangan.setEditable(false);
	}
	
	public void clearTextField(){
		txtFldKodeSupplier.setText("");
		txtFldNamaSupplier.setText("");
		txtFldNamaAgen.setText("");
		txtFldHpAgen.setText("");
		txtFldEmailAgen.setText("");
		txtFldKodePos.setText("");
		txtFldKota.setText("");
		txtFldTelepon.setText("");
		txtFldProvinsi.setText("");
		txtAreaAlamat.setText("");
		txtAreaKeterangan.setText("");
	}

}
